package com.mayikt.pay.controller;

import com.mayikt.pay.bo.NotifyMerchantBO;
import com.mayikt.pay.service.PayMessageTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;
import java.util.concurrent.ExecutionException;

@Slf4j
@RestController
public class WeChatTemplateController {
    @Autowired
    private PayMessageTemplate payMessageTemplate;

    /**
     * 测试代码
     */
    @GetMapping("/sendMsg")
    public String sendMsg() {
        return "ok";
    }

    //3332232.e3.luyouxia.net:13668
    //http://127.0.0.1:8076/testSend?merchantId=012231&merchantOpenId=oQ-Rz6C8bn3AxjhnZfHL5ubqjj-k&paymentAmount=300.20&payDate=2020-10-12%2010:10:10&paymentChannel=%E6%94%AF%E4%BB%98%E5%AE%9D&paymentId=15212521120
    @GetMapping("/testSend")
    public String testSend(String merchantId,
                           String merchantOpenId,
                           BigDecimal paymentAmount,
                           @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date payDate,
                           String paymentChannel, String paymentId) throws ExecutionException, InterruptedException {
        //获取异步返回的结果
        payMessageTemplate.notifyMerchantPaymentResultMQ(new NotifyMerchantBO(merchantId, merchantOpenId, paymentAmount, payDate, paymentChannel, paymentId));
        return "测试发送成功";

    }
}
